package com.google.gwt.dev;

import com.google.gwt.dev.InMemoryHostedModeBase.InMemoryBrowserWidgetHostImpl;
import com.google.gwt.dev.shell.ModuleSpaceHost;
import com.google.gwt.hmconsole.server.BrowserConnectionInfo;
import com.google.gwt.hmconsole.server.HostedModeState;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class InMemoryHostedModeState implements HostedModeState {

  private InMemoryBrowserWidgetHostImpl browserHost;

  public InMemoryHostedModeState(InMemoryBrowserWidgetHostImpl browserHost) {
    this.browserHost = browserHost;
  }

  public List<BrowserConnectionInfo> getBrowserConnections() {
    Map<ModuleSpaceHost, InMemoryModulePanel> moduleTabs = browserHost.getModuleTabs();

    List<BrowserConnectionInfo> result = new ArrayList<BrowserConnectionInfo>();
    for (InMemoryModulePanel panel : moduleTabs.values()) {
      BrowserConnectionInfoImpl conn = new BrowserConnectionInfoImpl();
      conn.browserName = panel.getLogger().getName();
      result.add(conn);
    }

    return result;
  }

  private static class BrowserConnectionInfoImpl implements
      BrowserConnectionInfo {

    private String browserName;

    public String getBrowserName() {
      return this.browserName;
    }

  }

}
